<template>
  <div class="app-container">
    <PageSearch :showSearch.sync="showSearch" :getList="getList" :handleQuery="handleQuery" :resetQuery="resetQuery">
      <template #form>
        <el-form :model="queryParams" ref="queryForm" size="small">
          <el-row>
            <el-form-item prop="timeBetween">
              <el-date-picker
                :start-placeholder="$t('开始时间')"
                :end-placeholder="$t('结束时间')"
                value-format="yyyy-MM-dd"
                v-model="queryParams.timeBetween"
                type="daterange"
              >
              </el-date-picker>
            </el-form-item>
            <!-- 订单平台 -->
            <el-form-item prop="shopType">
              <el-select :placeholder="$t('订单平台')" clearable v-model="queryParams.shopType">
                <el-option
                  :value="item.value"
                  :label="item.label"
                  v-for="(item, index) in shop_type_list"
                  :key="index"
                />
              </el-select>
            </el-form-item>
            <!-- 店铺名 -->
            <el-form-item prop="shopId">
              <el-select filterable :placeholder="$t('店铺名称')" clearable v-model="queryParams.shopId">
                <el-option
                  v-for="(item, index) in shopIdList"
                  :key="index"
                  :value="item.id"
                  :label="`${item.shopName}(${item.platformTypeName})`"
                />
              </el-select>
            </el-form-item>
            <!-- 库存是否充足 -->
            <el-form-item prop="isStockAdequate">
              <el-select :placeholder="$t('库存是否充足')" clearable v-model="queryParams.isStockAdequate">
                <el-option value="1" :label="$t('是')" />
                <el-option value="0" :label="$t('否')" />
              </el-select>
            </el-form-item>
            <!-- 是否生成包裹 -->
            <el-form-item prop="isPackage">
              <el-select :placeholder="$t('是否生成包裹')" clearable v-model="queryParams.isPackage">
                <el-option value="1" :label="$t('是')" />
                <el-option value="0" :label="$t('否')" />
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <!-- 是否付款结账 -->
            <el-form-item prop="isPayment">
              <el-select :placeholder="$t('是否付款结账')" clearable v-model="queryParams.isPayment">
                <el-option value="1" :label="$t('是')" />
                <el-option value="0" :label="$t('否')" />
              </el-select>
            </el-form-item>
            <el-form-item prop="skuNo">
              <el-input :placeholder="$t('sku编号')" @keyup.enter.native="handleQuery" v-model="queryParams.skuNo" />
            </el-form-item>
            <el-form-item prop="orderNo">
              <el-input :placeholder="$t('订单号')" @keyup.enter.native="handleQuery" v-model="queryParams.orderNo" />
            </el-form-item>
            <el-form-item prop="packageNo">
              <el-input :placeholder="$t('包裹号')" @keyup.enter.native="handleQuery" v-model="queryParams.packageNo" />
            </el-form-item>
            <el-form-item prop="deliveryNo">
              <el-input
                :placeholder="$t('快递号')"
                @keyup.enter.native="handleQuery"
                v-model="queryParams.deliveryNo"
              />
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="isOutWarehouse ">
              <el-select @change="getList" :placeholder="$t('全部出库')" clearable v-model="queryParams.isOutWarehouse">
                <el-option value="1" :label="$t('是')" />
                <el-option value="0" :label="$t('否')" />
              </el-select>
            </el-form-item>
            <el-form-item prop="distrId" v-show="$store.state.user.userType == 'sys_user'">
              <el-select :placeholder="$t('租户')" clearable v-model="queryParams.distrId" @change="handleQuery">
                <el-option v-for="item in distrList" :label="item.name" :value="item.distrId" :key="item.id" />
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </template>
      <template #actions>
        <div style="margin-right: 10px" v-hasPermi="['distribution:distribution:importPlatformData']">
          <span style="font-size: 14px; font-weight: 700; color: #606266">
            <!-- 订单平台 -->
            {{ $t('订单平台') }}
          </span>
          <el-select
            @change="handleTypeChange"
            class="importantData"
            size="mini"
            clearable
            filterable
            v-model="importDataForm.platformType"
          >
            <el-option :value="item.value" :label="item.label" v-for="(item, index) in shop_type_list" :key="index" />
          </el-select>
          <el-button class="importantDataBtn" @click="checkFileData" type="warning" size="mini">
            <!-- 导入 -->
            {{ $t('导入') }}
          </el-button>
        </div>
        <el-button v-hasPermi="['distribution:orderBatch:skuList']" size="mini" @click="handleUnSendsku">
          <!-- 当前sku缺货情况 -->
          {{ $t('当前sku缺货情况') }}
        </el-button>
        <el-button v-hasPermi="['distribution:orderBatch:updateStockFlag']" size="mini" @click="relaodUpdateStockFlag">
          <!-- 更新库存核销 -->
          {{ $t('更新库存核销') }}
        </el-button>
        <el-button
          v-hasPermi="['distribution:order:generatePackage']"
          size="mini"
          :disabled="tableCheck.length == 0"
          @click="generatePackage"
        >
          <!-- 生成包裹 -->
          {{ $t('生成包裹') }}
        </el-button>

        <el-button v-hasPermi="['distribution:googleRouteBatch:list']" size="mini" @click="handleSelectDispatch">
          {{ $t('选择自派送') }}
        </el-button>

        <el-button
          :disabled="tableCheck.length == 0"
          v-hasPermi="['distribution:order:exportPackage']"
          size="mini"
          @click="checkFileDataExprort"
        >
          <!-- 导出包裹 -->
          {{ $t('导出包裹') }}
        </el-button>
        <el-button v-hasPermi="['distribution:order:exportExpressSheet']" size="mini" @click="handleExportExpressSheet">
          <!-- 导出面单 -->
          {{ $t('导出面单') }}
        </el-button>
        <el-button
          v-hasPermi="['distribution:order:importPackageExpressNo:Hm']"
          size="mini"
          @click="
            () => {
              importInfo.query.packageExpressType = 1
              importInfo.show = true
            }
          "
        >
          <!-- 导入黑猫快递单号 -->
          {{ $t('导入黑猫快递单号') }}
        </el-button>
        <el-button
          v-hasPermi="['distribution:order:importPackageExpressNo:Zc']"
          size="mini"
          @click="
            () => {
              importInfo.query.packageExpressType = 2
              importInfo.show = true
            }
          "
        >
          <!-- 导入佐川快递单号 -->
          {{ $t('导入佐川快递单号') }}
        </el-button>

        <el-button
          v-hasPermi="['distribution:order:statisticalExpress']"
          :disabled="tableCheck.length == 0"
          size="mini"
          @click="handleExpressStatics"
        >
          {{ $t('快递统计') }}
        </el-button>
        <el-button
          :disabled="tableCheck.length == 0"
          size="mini"
          @click="handleTryAutoPay"
          v-hasPermi="['distribution:order:tryPayBatch']"
        >
          {{ $t('尝试自动付款按钮') }}
        </el-button>
      </template>
    </PageSearch>
    <div class="FitHeader">
      <el-table
        :height="calTableHeight()"
        v-loading="loading"
        ref="TableRef"
        :data="tableData"
        row-key="menuId"
        @selection-change="(rows) => (tableCheck = rows)"
      >
        <el-table-column type="selection" :selectable="selectable" width="55"> </el-table-column>
        <!-- 租户 -->
        <el-table-column show-overflow-tooltip :label="$t('租户')" align="center" prop="distrName" width="180" />
        <!-- 订单平台 -->
        <!-- <el-table-column show-overflow-tooltip :label="$t('订单平台')" align="center" prop="type" width="120">
          <template slot-scope="{ row }">
            <div
              :style="{
                color: row.shopType == 9 ? 'red' : '',
              }">
              {{ handleType(row.shopType) }}
            </div>
          </template>
        </el-table-column> -->
        <!-- 店铺名 -->
        <el-table-column
          show-overflow-tooltip
          align="center"
          :label="$t('店铺名称/订单平台')"
          width="150"
          prop="shopName"
        >
          <template slot-scope="{ row }">
            <el-button style="padding: 0" type="text" @click="showShopName(row)">
              {{ row.shopName }}
            </el-button>
            <div
              :style="{
                color: row.shopType == 9 ? 'red' : '',
              }"
            >
              {{ handleType(row.shopType) }}
            </div>
          </template>
        </el-table-column>
        <!-- 创建时间 -->
        <el-table-column show-overflow-tooltip width="150" :label="$t('创建时间')" align="center" prop="createTime" />
        <el-table-column show-overflow-tooltip :label="$t('是否生成发送通知')" align="center" prop="isSendMsg">
          <template slot-scope="{ row }">
            <!-- 是否生成包裹  否不能点击-->
            <el-popconfirm @confirm="isautoPackage(row)" :title="$t('确定') + '?'">
              <el-link type="danger" slot="reference" :underline="false">
                <el-button
                  type="text"
                  v-if="row.isSendMsg == 1"
                  :disabled="!isdisAbel || row.isPackage == 0"
                  style="color: green"
                >
                  {{ $t('是') }}
                </el-button>
              </el-link>
            </el-popconfirm>
            <el-popconfirm @confirm="isautoPackage(row)" :title="$t('确定') + '?'">
              <el-link type="danger" slot="reference" :underline="false">
                <el-button type="text" v-if="row.isSendMsg == 0" :disabled="!isdisAbel || row.isPackage == 0">
                  {{ $t('否') }}
                </el-button>
              </el-link>
            </el-popconfirm>
          </template>
        </el-table-column>
        <!-- 是否错误 -->
        <el-table-column :label="$t('是否错误')" align="center" prop="isError">
          <template slot-scope="{ row }">
            <!-- 是否有错误 0:否 1：是 -->
            <!-- <div v-if="row.isError == 0">
              {{ $t('否') }}
            </div>
            <div v-if="row.isError == 1">
              <el-link type="danger" :underline="false">
                {{ $t('是') }}
              </el-link>
            </div> -->
            <RightOrWrong :count="row.isError == 0 ? 1 : 0"></RightOrWrong>
          </template>
        </el-table-column>

        <!-- 库存是否充足 -->
        <el-table-column show-overflow-tooltip :label="$t('库存是否充足')" align="center" prop="isStockAdequate">
          <template slot-scope="{ row }">
            <!-- <div style="color: green" v-if="row.isStockAdequate == 1">
              {{ $t('是') }}
            </div>
            <div style="color: red" v-if="row.isStockAdequate == 0">
              {{ $t('否') }}
            </div> -->
            <RightOrWrong style="cursor: pointer" :count="row.isStockAdequate" />
          </template>
        </el-table-column>
        <!-- 是否生成包裹 -->
        <el-table-column show-overflow-tooltip :label="$t('是否生成包裹')" align="center" prop="isPackage">
          <template slot-scope="{ row }">
            <RightOrWrong :count="row.isPackage" />
          </template>
        </el-table-column>

        <!-- sku账单是否付款结账 -->
        <el-table-column show-overflow-tooltip :label="$t('sku账单是否付款结账')" align="center" prop="billSkuPay">
          <template slot-scope="{ row }">
            <RightOrWrong :count="row.billSkuPay" />
          </template>
        </el-table-column>
        <!-- 包裹账单是否付款结账 -->
        <el-table-column width="100" :label="$t('包裹账单是否付款结账')" align="center" prop="billPackagePay">
          <template slot-scope="{ row }">
            <RightOrWrong :count="row.billPackagePay" />
          </template>
        </el-table-column>
        <!-- 捆包账单是否付款结账 -->
        <el-table-column show-overflow-tooltip :label="$t('捆包账单是否付款结账')" align="center" prop="billBundlePay">
          <template slot-scope="{ row }">
            <RightOrWrong :count="row.billBundlePay" />
          </template>
        </el-table-column>
        <!-- 手续费账单是否付款结账 -->
        <el-table-column
          show-overflow-tooltip
          :label="$t('手续费账单是否付款结账')"
          align="center"
          prop="billCommissionPay"
        >
          <template slot-scope="{ row }">
            <RightOrWrong :count="row.billCommissionPay" />
          </template>
        </el-table-column>
        <!-- 是否出库 -->
        <el-table-column show-overflow-tooltip :label="$t('是否出库')" align="center" prop="isOutWarehouse">
          <template slot-scope="{ row }">
            <RightOrWrong :count="row.isOutWarehouse" />
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column
          show-overflow-tooltip
          :label="$t('操作')"
          align="center"
          fixed="right"
          prop="isPayment"
          :width="calWidth(150, 200, 150)"
        >
          <template slot-scope="{ row }">
            <!-- 确认删除批次 -->
            <el-popconfirm
              @confirm="handleBatchDelete(row.id)"
              :title="$t('确定删除?')"
              v-show="row.isPackage == 0"
              v-hasPermi="['distribution:orderBatch:remove']"
            >
              <el-button type="text" style="color: red" slot="reference" :underline="false">
                <!-- 批次删除 -->
                {{ $t('删除') }}
              </el-button>
            </el-popconfirm>
            <!-- 批次包裹回滚 -->
            <el-popconfirm
              @confirm="backBatch(row.id)"
              :title="$t('确定回滚当前批次?')"
              v-show="row.billPackagePay == 0 && row.isPackage == 1 && row.isOutWarehouse == 0"
              v-hasPermi="['distribution:order:batchPackageRollback']"
            >
              <el-button type="text" slot="reference" :underline="false">
                <!-- 批次删除 -->
                {{ $t('批次包裹回滚') }}
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
      v-show="pageTotal > 0"
      :total="pageTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 订单导入 -->
    <el-dialog
      :title="$t('导入') + platformType"
      destroy-on-close
      :visible.sync="importDataForm.uplaodopen"
      width="400px"
      append-to-body
    >
      <!-- :onChange="onChange" -->
      <el-upload
        ref="uploadRef"
        :limit="importDataForm.limit"
        :accept="handleAccept()"
        :headers="importDataForm.headers"
        action="/"
        :disabled="importDataForm.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <!-- <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div> -->
        <div class="el-upload__text">{{ $t('将文件拖到此处，或点击上传') }}</div>
      </el-upload>

      <div v-html="importDataForm.tip" v-if="importDataForm.tip" style="margin: 5px; padding: 5px" type="warning"></div>
      <div
        v-if="importDataForm.alert"
        v-html="importDataForm.alert"
        style="border: 2px solid #565252; padding: 5px; border-radius: 5px"
      ></div>

      <div v-if="importDataForm.showDownloadMercariTemplate">
        <el-button type="text" @click="downloadMercariTemplate"> 下载煤炉个人模板 </el-button>
      </div>

      <div style="text-align: right; margin: 10px 0">
        <el-button type="primary" @click="handleUpload">{{ $t('上传') }}</el-button>
      </div>
    </el-dialog>
    <!-- 批次详细信息 -->
    <el-dialog
      :title="$t('详情')"
      destroy-on-close
      append-to-body
      :visible.sync="batchData.Show"
      width="700px"
      :before-close="batchDataHandleClose"
    >
      <template #title>
        <el-row>
          <el-col :span="8"> {{ $t('详情') }} </el-col>
          <el-col :span="8">
            <div
              :title="batchData.formData.shopName"
              style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis"
            >
              店铺名:{{ batchData.formData.shopName }}
            </div>
          </el-col>
          <el-col :span="7">
            <div>时间:{{ batchData.formData.createTime }}</div>
          </el-col>
        </el-row>
      </template>
      <el-row style="margin-bottom: 20px">
        <el-col :span="8">
          <!-- 订单数量 -->
          {{ $t('订单数量') }}:
          <span @click="lookOrderInfor" style="color: blue; cursor: pointer">
            {{ batchData.orderNum }}
          </span>
        </el-col>
        <el-col :span="8">
          <!-- 营业额： -->
          {{ $t('营业额') }}:
          {{ batchData.turnoverAll }}
        </el-col>
        <el-col :span="8">
          <!-- 手续费： -->
          {{ $t('手续费') }}:
          {{ (+batchData.commissionAll).toFixed() + 'JPY' }}
        </el-col>
      </el-row>
      <el-row style="margin-bottom: 20px">
        <el-col :span="8">
          <!-- sku种类： -->
          {{ $t('系统sku种类') }}:
          <span @click="showBactchSku" style="color: blue; cursor: pointer">
            {{ batchData.skuCateNum }}
          </span>
        </el-col>
        <el-col :span="8">
          <!-- sku数量： -->
          {{ $t('sku数量') }}:
          {{ batchData.skuNum }}
        </el-col>

        <el-col :span="8">
          <!-- sku费用： -->
          {{ $t('sku费用') }}:
          <span @click="skuFeeInfo.show = true" style="color: blue; cursor: pointer">
            {{ batchData.skuCost ? (+batchData.skuCost).toFixed() + 'JPY' : '' }}
          </span>
        </el-col>
      </el-row>
      <el-row style="margin-bottom: 20px">
        <el-col :span="8">
          {{ $t('店铺sku种类') }}:
          <span style="color: blue; cursor: pointer" @click="hanldeShopSkuNum(batchData)">
            {{ batchData.shopSkuNum }}
          </span>
        </el-col>
        <el-col :span="8">
          <!-- 快递： -->
          {{ $t('快递') }}:
          {{ batchData.packageCost ? (+batchData.packageCost).toFixed() : '' }}
        </el-col>
        <el-col :span="8">
          <!-- 捆包费用： -->
          {{ $t('捆包费用') }}:
          {{ batchData.packageBaleCost ? (+batchData.packageBaleCost).toFixed() + 'JPY' : '' }}
        </el-col>
      </el-row>
      <el-row style="margin-bottom: 20px">
        <el-col :span="8">
          {{ $t('包裹数量') }}:
          <span @click="handlePackageNum" style="color: blue; cursor: pointer">
            {{ batchData.packageNum || 0 }}
          </span>
        </el-col>
        <el-col :span="8">
          <!-- 消费税： -->
          {{ $t('消费税') }}:
          {{ batchData.taxAll }}
        </el-col>
        <el-col :span="8">
          <!-- 捆包费用： -->
          {{ $t('利润') }}:
          {{
            (
              batchData.turnoverAll -
              batchData.skuCost -
              batchData.commissionAll -
              batchData.packageCost -
              batchData.packageBaleCost
            ).toFixed() + 'JPY'
          }}
        </el-col>
      </el-row>

      <el-row v-hasPermi="['distribution:order:preTestGeneratePackage']">
        <el-col :span="8">
          <el-button @click="handlePackageNumTest" size="small" type="primary"> 测试生成快递方式 </el-button>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button @click="batchDataHandleClose">
          <!-- 关闭 -->
          {{ $t('关闭') }}
        </el-button>
      </div>
    </el-dialog>
    <!-- 订单项详情列表 -->
    <el-dialog
      :title="$t('主单详情')"
      destroy-on-close
      append-to-body
      :visible.sync="mainOrderInfo.show"
      width="90%"
      :before-close="() => (mainOrderInfo.show = false)"
    >
      <el-alert
        :title="$t('包裹生成后不能编辑')"
        show-icon
        :closable="false"
        effect="dark"
        style="margin-bottom: 20px"
        type="warning"
      >
      </el-alert>
      <!-- *************************************搜索区************************************* -->
      <el-form
        :model="mainOrderInfo.queryParams"
        ref="mainOrderInfo.queryParams"
        @submit.native.prevent
        size="small"
        :inline="true"
      >
        <!-- 订单号 -->
        <el-form-item :label="$t('订单号')" prop="orderNo">
          <el-input v-model="mainOrderInfo.queryParams.orderNo" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getdistributionOrder">
            <!-- 搜索 -->
            {{ $t('搜索') }}
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetFormData">
            <!-- 重置 -->
            {{ $t('重置') }}
          </el-button>
        </el-form-item>
      </el-form>
      <el-table
        :row-class-name="({ row }) => handleRowClassName(row)"
        v-loading="loading"
        show-summary
        :height="calTableHeight() - 100"
        :summary-method="
          (e) =>
            handleSum(e, [
              'turnover',
              'tax',
              'payAmount',
              'freightSkuAmount',
              'skuTotalAmount',
              'useShopCouponAmount',
              'usePlatformCouponAmount',
              'useCouponTotal',
              'usePoints',
              'returnPoints',
            ])
        "
        ref="TableRef"
        :data="mainOrderInfo.data"
      >
        <!-- 序号 -->
        <el-table-column :label="$t('序号')" align="center" type="index" />
        <!-- 订单id -->
        <el-table-column show-overflow-tooltip :label="$t('订单号')" width="180" align="center" prop="orderNo" />
        <!-- 收货人 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人')" align="center" prop="receiveName">
        </el-table-column>
        <!-- 收货人电话 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人电话')" align="center" prop="receivePhone">
        </el-table-column>

        <!-- 收货人地址 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人地址')" align="center" width="120" prop="address1">
          <template slot-scope="{ row }">
            <span>{{ handleReceiveAddress(row) }}</span>
          </template>
        </el-table-column>
        <!-- 包裹号 -->
        <el-table-column show-overflow-tooltip :label="$t('包裹号')" align="center" prop="packageNo"> </el-table-column>
        <!-- 取消订单 -->
        <el-table-column show-overflow-tooltip :label="$t('取消订单')" align="center" prop="delFlag">
          <template slot-scope="{ row }">
            <!-- 取消订单 0：否，1：是 -->
            <div style="color: green" v-if="row.delFlag == 0">
              {{ $t('否') }}
            </div>
            <div style="color: red" v-if="row.delFlag == 2">
              {{ $t('是') }}
            </div>
          </template>
        </el-table-column>
        <!-- 是否错误 -->
        <el-table-column show-overflow-tooltip :label="$t('是否错误')" align="center" prop="error">
          <template slot-scope="{ row }">
            <!-- 是否有错误 0：无 1：有 -->
            <div style="color: green" v-if="row.error == 0">
              {{ $t('否') }}
            </div>
            <div style="color: red" v-if="row.error == 1">
              <div>{{ $t('是') }}</div>
              <div>{{ row.errorMsg }}</div>
            </div>
          </template>
        </el-table-column>
        <!-- 是否重复 -->
        <el-table-column show-overflow-tooltip :label="$t('是否重复')" align="center" prop="repeatFlag">
          <template slot-scope="{ row }">
            <div v-if="row.repeatFlag == 1">
              <!-- 是 -->
              {{ $t('是') }}
            </div>
            <div v-if="row.repeatFlag == 0">
              <!-- 否 -->
              {{ $t('否') }}
            </div>
          </template>
        </el-table-column>

        <!-- 营业额 -->
        <el-table-column
          show-overflow-tooltip
          :label="$t('营业额') + '(JPY)'"
          align="center"
          prop="turnover"
          width="100"
        />
        <!-- 消费税 -->
        <el-table-column show-overflow-tooltip :label="$t('消费税')" align="center" prop="tax" />
        <!-- 付款金额 -->
        <el-table-column show-overflow-tooltip :label="$t('付款金额')" align="center" prop="payAmount" />
        <!-- 运费合计商品金额 -->
        <el-table-column show-overflow-tooltip :label="$t('运费合计商品金额')" align="center" prop="freightSkuAmount" />
        <!-- 商品合计金额 -->
        <el-table-column show-overflow-tooltip :label="$t('商品合计金额')" align="center" prop="skuTotalAmount" />
        <!-- 使用店铺发行优惠券 -->
        <el-table-column
          show-overflow-tooltip
          :label="$t('使用店铺发行优惠券')"
          align="center"
          prop="useShopCouponAmount"
        />
        <!-- 使用平台发行优惠券 -->
        <el-table-column
          show-overflow-tooltip
          :label="$t('使用平台发行优惠券')"
          align="center"
          prop="usePlatformCouponAmount"
        />
        <!-- 使用优惠券合计 -->
        <el-table-column show-overflow-tooltip :label="$t('使用优惠券合计')" align="center" prop="useCouponTotal" />
        <!-- 使用积分 -->
        <el-table-column show-overflow-tooltip :label="$t('使用积分')" align="center" prop="usePoints" />
        <!-- 返点 -->
        <el-table-column show-overflow-tooltip :label="$t('返点')" align="center" prop="returnPoints" />
        <el-table-column label="sku" align="center" prop="sku" :width="mainOrderInfo.skuWidth">
          <template slot-scope="{ row }">
            <div class="sku-list">
              <div v-for="item in row.skus" class="sku-list-item">
                <div class="skuNo">{{ item.skuNo }}</div>
                <el-image
                  :key="Math.random()"
                  v-hover="item.imgUrl"
                  style="width: 30px; height: 30px"
                  fit="contain"
                  :src="item.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'"
                />
                <div>{{ item.orderSkuNum }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column
          :label="$t('操作')"
          align="center"
          fixed="right"
          prop="isPayment"
          :width="calWidth(200, 250, 200)"
        >
          <template slot-scope="{ row }">
            <!-- 增加是否错误字段 error和 编辑按钮  （当row数据里 error = 1时 有编辑按钮） -->
            <!-- v-if="row.packageNo == null" -->
            <el-link
              :underline="false"
              type="primary"
              v-show="row.packageNo == null"
              style="margin: 0 10px"
              @click="handleEditMainOrder(row)"
              v-hasPermi="['distribution:order:edit']"
            >
              编辑
            </el-link>
            <!-- packageNo有值不能删除 -->
            <el-popconfirm
              v-show="!row.packageNo"
              @confirm="handleDelete(row.id)"
              title="确认删除?"
              v-hasPermi="['distribution:order:remove']"
            >
              <el-link :underline="false" type="danger" slot="reference">删除</el-link>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <!-- <pagination v-show="mainOrderInfo.pageTotal > 0" :total="mainOrderInfo.pageTotal"
        :page.sync="mainOrderInfo.queryParams.pageNum" :limit.sync="mainOrderInfo.queryParams.pageSize"
        @pagination="getdistributionOrder" /> -->
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="
            () => {
              mainOrderInfo.show = false
            }
          "
          >关闭</el-button
        >
      </div>
    </el-dialog>
    <!-- 当前订单sku(聚合)  -->
    <el-dialog
      :title="$t('当前订单sku(聚合)')"
      destroy-on-close
      append-to-body
      :visible.sync="batchSkuInfo.show"
      width="800px"
      :before-close="
        () => {
          batchSkuInfo.show = false
        }
      "
    >
      <!-- *************************************搜索区************************************* -->
      <el-form
        @submit.native.prevent
        :model="batchSkuInfo.queryParams"
        ref="batchSkuInfo.queryParams"
        size="small"
        :inline="true"
      >
        <!-- 订单号 -->
        <el-form-item :label="$t('sku编号')" prop="skuNo">
          <el-input v-model="batchSkuInfo.queryParams.skuNo" clearable @keyup.enter.native="getBatchSkuList" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getBatchSkuList">
            <!-- 搜索 -->
            {{ $t('搜索') }}
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetSkuNo">
            <!-- 重置 -->
            {{ $t('重置') }}
          </el-button>
        </el-form-item>
      </el-form>
      <!-- 使用数量统计 -->
      <el-table
        ref="TableRef"
        :data="batchSkuInfo.data"
        :summary-method="(e) => handleSum(e, ['orderSkuNumAll'], $t('使用数量'))"
        show-summary
      >
        <!-- 序号 -->
        <el-table-column :label="$t('序号')" align="center" type="index" />
        <el-table-column show-overflow-tooltip label="skuNo" align="center" prop="skuNo" />
        <el-table-column show-overflow-tooltip :label="$t('库位号')" align="center" prop="spNo" />
        <el-table-column label="图片" align="center">
          <template slot-scope="{ row }">
            <el-image
              :key="Math.random()"
              v-hover="row.imgUrl"
              style="width: 50px; height: 50px"
              fit="contain"
              :src="row.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'"
            />
          </template>
        </el-table-column>
        <!-- 可用数量 -->
        <el-table-column show-overflow-tooltip :label="$t('可用数量')" align="center" prop="stock" />
        <!-- 使用数量 -->
        <el-table-column show-overflow-tooltip :label="$t('使用数量')" align="center" prop="orderSkuNumAll" />
      </el-table>
      <pagination
        v-show="batchSkuInfo.pageTotal > 0"
        :total="batchSkuInfo.pageTotal"
        :page.sync="batchSkuInfo.queryParams.pageNum"
        :limit.sync="batchSkuInfo.queryParams.pageSize"
        @pagination="getBatchSkuList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="batchSkuInfo.show = false">
          <!-- 关闭 -->
          {{ $t('关闭') }}
        </el-button>
      </div>
    </el-dialog>
    <!-- 未发货批次SKU ===>当前sku缺货情况 -->
    <el-dialog width="1100px" title="缺货情况" destroy-on-close :visible.sync="unSendskuInfo.show" append-to-body>
      <el-form :model="unSendskuInfo.queryParams" size="small" :inline="true">
        <!-- sku编号 -->
        <el-form-item :label="$t('sku编号')" prop="skuNo">
          <el-input v-model="unSendskuInfo.queryParams.skuNo" clearable @keyup.enter.native="getUnSendskuList" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getUnSendskuList">
            <!-- 搜索 -->
            {{ $t('搜索') }}
          </el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" style="margin-bottom: 8px">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            :disabled="tableCheckPay.length == 0"
            size="mini"
            @click="handleBatchPrePay"
          >
            {{ $t('批量提前付款') }}
          </el-button>
        </el-col>
      </el-row>
      <el-table
        ref="TableRef"
        @selection-change="(rows) => (tableCheckPay = rows)"
        :data="unSendskuInfo.data"
        row-key="menuId"
      >
        <el-table-column
          :selectable="(row) => row.applyFlag == 0"
          show-overflow-tooltip
          type="selection"
          width="55"
          align="center"
        />
        <!-- sku编号 -->
        <el-table-column :label="$t('sku')" width="110" align="center" prop="skuNo" />
        <!-- 图片 -->
        <el-table-column :label="$t('图片')" align="center" prop="imgUrl">
          <template slot-scope="{ row }">
            <el-image
              :key="Math.random()"
              v-hover="row.imgUrl"
              fit="contain"
              style="width: 50px; height: 50px"
              :src="row.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'"
            />
          </template>
        </el-table-column>
        <!-- 当前库存数量 -->
        <el-table-column show-overflow-tooltip :label="$t('当前库存数量')" align="center" prop="stock" />

        <!-- 需要数量 -->
        <el-table-column show-overflow-tooltip :label="$t('需要数量')" align="center" prop="orderSkuNumAll" />
        <!-- 可申请数量 -->
        <el-table-column show-overflow-tooltip :label="$t('可申请数量')" align="center" prop="cloudStock" />
        <!-- 当前价格 -->
        <el-table-column show-overflow-tooltip :label="$t('当前价格')" align="center" prop="cloudPrice" />
        <!-- 待出账单数量 -->
        <el-table-column show-overflow-tooltip :label="$t('待出账单数量')" align="center" prop="waitBillNum" />
        <!-- 付款数量 -->
        <el-table-column show-overflow-tooltip :label="$t('付款数量')" align="center" prop="payNum" />
        <!-- 申请数量 -->
        <el-table-column :label="$t('申请数')" width="100" align="center" prop="applyNum">
          <template slot-scope="{ row }">
            <el-input v-model="row.applyNum" :max="row.cloudStock" style="width: 80px" />
          </template>
        </el-table-column>

        <!-- 操作 -->
        <el-table-column :label="$t('操作')" :width="calWidth(150, 200, 200)" align="center" fixed="right">
          <template slot-scope="{ row }">
            <el-button
              v-show="row.applyFlag !== 0"
              type="text"
              v-hasPermi="['distribution:skuDistributor:listCloud']"
              @click="goToApply(row)"
            >
              <!-- 编辑 -->
              {{ $t('申请') }}
            </el-button>
            <el-button
              v-show="row.applyFlag == 0"
              type="text"
              v-hasPermi="['distribution:skuSellerApply:listSellerApply']"
              @click="handlePay(row)"
            >
              <!-- 编辑 -->
              {{ $t('提前付款') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="unSendskuInfo.pageTotal > 0"
        :total="unSendskuInfo.pageTotal"
        :page.sync="unSendskuInfo.queryParams.pageNum"
        :limit.sync="unSendskuInfo.queryParams.pageSize"
        @pagination="getUnSendskuList"
      />
    </el-dialog>

    <!-- 捆包详情（不分页,最后一行做价格统计） -->
    <el-dialog
      :title="$t('捆包详情')"
      destroy-on-close
      append-to-body
      :visible.sync="packageInfo.show"
      width="90%"
      :before-close="() => (packageInfo.show = false)"
    >
      <!-- *************************************搜索区************************************* -->
      <el-form
        @submit.native.prevent
        :model="packageInfo.queryParams"
        ref="packageInfo.queryParams"
        size="small"
        :inline="true"
      >
        <!-- 包裹号 -->
        <el-form-item prop="packageNo">
          <el-input
            v-model="packageInfo.queryParams.packageNo"
            :placeholder="$t('包裹号')"
            clearable
            @keyup.enter.native="getOrderPackageList"
          />
        </el-form-item>
        <el-form-item prop="deliveryNo">
          <el-input
            :placeholder="$t('快递号')"
            @keyup.enter.native="getOrderPackageList"
            v-model="packageInfo.queryParams.deliveryNo"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getOrderPackageList">
            <!-- 搜索 -->
            {{ $t('搜索') }}
          </el-button>
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="
              () => {
                packageInfo.queryParams.packageNo = ''
                packageInfo.queryParams.deliveryNo = ''
                getOrderPackageList()
              }
            "
          >
            <!-- 重置 -->
            {{ $t('重置') }}
          </el-button>
        </el-form-item>
      </el-form>
      <el-row class="mb8">
        <el-button
          type="primary"
          size="mini"
          @click="handleExportOverWeightPacage"
          v-hasPermi="['distribution:order:exportOverweightPackage']"
        >
          {{ $t('导出超规格包裹') }}
        </el-button>
      </el-row>
      <el-table
        :row-class-name="({ row }) => handleRowClassName(row)"
        show-summary
        :summary-method="(e) => handleSum(e, ['deliveryFee', 'bundleFee'])"
        ref="TableRef"
        :data="packageInfo.data"
        max-height="600"
      >
        <el-table-column :label="$t('序号')" align="center" type="index" width="50" />
        <el-table-column show-overflow-tooltip :label="$t('包裹号')" align="center" prop="packageNo">
          <template slot-scope="{ row }">
            <div>{{ row.packageNo ? row.packageNo.toString() : '' }}</div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip :label="$t('订单号')" align="center" prop="orderNos" width="200">
          <template slot-scope="{ row }">
            <div>{{ row.orderNos ? row.orderNos.toString() : '' }}</div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          :label="$t('快递标识号')"
          align="center"
          width="100"
          prop="deliveryWayFinal"
        >
          <template slot-scope="{ row }">
            <div :style="row.deliveryWayFinal == '超规格' ? 'color:red' : ''">
              {{ row.deliveryWayFinal }}
            </div>
          </template>
        </el-table-column>

        <el-table-column show-overflow-tooltip :label="$t('快递单号')" align="center" prop="deliveryNos" width="200">
          <template slot-scope="{ row }">
            <div>{{ row.deliveryNos ? row.deliveryNos.toString() : '' }}</div>
          </template>
        </el-table-column>
        <!-- 收货人 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人')" align="center" prop="receiveName" />
        <!-- 收货人电话 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人电话')" align="center" prop="receivePhone">
        </el-table-column>
        <!-- 收货人地址 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人地址')" align="center" prop="address1">
          <template slot-scope="{ row }">
            <span>{{ handleReceiveAddress(row) }}</span>
          </template>
        </el-table-column>
        <!-- 订单数量 -->
        <el-table-column show-overflow-tooltip :label="$t('订单数量')" align="center" prop="num">
          <template slot-scope="{ row }">
            <span
              style="color: blue; cursor: pointer"
              @click="
                () => {
                  packageInfo.order.query.orderBatchId = row.orderBatchId
                  packageInfo.order.query.packageNo = row.packageNo
                  packageInfo.order.show = true
                }
              "
            >
              {{ row.num }}
            </span>
          </template>
        </el-table-column>
        <!-- 包裹数量 -->
        <el-table-column show-overflow-tooltip :label="$t('包裹数量')" align="center" width="80" prop="packageNum" />
        <!-- 运费 -->
        <el-table-column show-overflow-tooltip :label="$t('运费')" align="center" width="80" prop="deliveryFee">
          <template slot-scope="{ row }">
            <div>{{ row.deliveryFee ? (+row.deliveryFee).toFixed() : '' }}</div>
          </template>
        </el-table-column>
        <!-- 捆包费 -->
        <el-table-column show-overflow-tooltip :label="$t('捆包费用')" align="center" width="80" prop="bundleFee">
          <template slot-scope="{ row }">
            <div>{{ row.bundleFee ? (+row.bundleFee).toFixed() : '' }}</div>
          </template>
        </el-table-column>
        <!-- 取消订单 -->
        <el-table-column show-overflow-tooltip :label="$t('取消订单')" align="center" prop="delFlag">
          <template slot-scope="{ row }">
            <!-- 取消订单 0：否，1：是 -->
            <div style="color: green" v-if="row.delFlag == 0">
              {{ $t('否') }}
            </div>
            <div style="color: red" v-if="row.delFlag == 2">
              {{ $t('是') }}
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip :label="$t('是否出库')" align="center" prop="isOutWarehouse">
          <template slot-scope="{ row }">
            <div v-if="row.isOutWarehouse == 1">
              <!-- 是 -->
              {{ $t('是') }}
            </div>
            <div v-if="row.isOutWarehouse == 0">
              <!-- 否 -->
              {{ $t('否') }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="sku" align="center" prop="sku" :width="packageInfo.skuWidth">
          <template slot-scope="{ row }">
            <div class="sku-list">
              <div v-for="item in row.skus" class="sku-list-item">
                <div class="skuNo">{{ item.skuNo }}</div>
                <el-image
                  :key="Math.random()"
                  v-hover="item.imgUrl"
                  fit="contain"
                  style="width: 30px; height: 30px"
                  :src="item.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'"
                />
                <div>{{ item.orderSkuNum }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column :label="$t('操作')" :width="calWidth(200, 300, 300)" align="center" fixed="right">
          <template slot-scope="{ row }">
            <el-button type="text" @click="handlePackageDetail(row)">
              {{ $t('查看') }}
            </el-button>
            <el-button type="text" v-hasPermi="['distribution:orderPackage:edit']" @click="editPackage(row)">
              {{ $t('修改快递') }}
            </el-button>
            <!-- 增加删除包裹按钮 delFlag = 0 才有按钮  -->
            <el-button
              v-show="row.delFlag == 0"
              type="text"
              v-hasPermi="['distribution:orderPackage:deletePackage']"
              @click="deletePackage(row)"
            >
              {{ $t('删除') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button @click="packageInfo.show = false">
          <!-- 关闭 -->
          {{ $t('关闭') }}
        </el-button>
      </div>
    </el-dialog>

    <!-- 生成测试快递方式 -->
    <el-dialog
      :title="$t('测试生成快递方式')"
      destroy-on-close
      append-to-body
      :visible.sync="ListOfExpressWays.show"
      width="90%"
      :before-close="() => (ListOfExpressWays.show = false)"
    >
      <el-table
        :row-class-name="({ row }) => handleRowClassName(row)"
        show-summary
        :summary-method="(e) => handleSum(e, ['deliveryFee', 'bundleFee'])"
        ref="TableRef"
        :data="ListOfExpressWays.data"
        max-height="600"
      >
        <!-- 序号 -->
        <el-table-column :label="$t('序号')" align="center" type="index" width="50" />
        <!-- 包裹号 -->
        <el-table-column show-overflow-tooltip :label="$t('包裹号')" align="center" prop="packageNo" width="180" />
        <!-- 快递标识号 -->
        <el-table-column
          show-overflow-tooltip
          :label="$t('快递标识号')"
          align="center"
          width="100"
          prop="deliveryWayFinal"
        />

        <!-- 收货人 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人')" align="center" prop="receiveName" />
        <!-- 收货人电话 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人电话')" align="center" prop="receivePhone">
        </el-table-column>
        <!-- 收货人地址 -->
        <el-table-column show-overflow-tooltip :label="$t('收货人地址')" align="center" prop="address1">
          <template slot-scope="{ row }">
            <span>{{ handleReceiveAddress(row) }}</span>
          </template>
        </el-table-column>
        <!-- 订单数量 -->
        <el-table-column show-overflow-tooltip :label="$t('订单数量')" align="center" prop="num">
          <template slot-scope="{ row }">
            <span style="color: blue; cursor: pointer" @click="setOrderNum(row)">
              {{ row.num }}
            </span>
          </template>
        </el-table-column>
        <!-- 包裹数量 -->
        <el-table-column show-overflow-tooltip :label="$t('包裹数量')" align="center" width="80" prop="packageNum" />
        <!-- 运费 -->
        <el-table-column show-overflow-tooltip :label="$t('运费')" align="center" width="80" prop="deliveryFee" />
        <!-- 捆包费 -->
        <el-table-column show-overflow-tooltip :label="$t('捆包费用')" align="center" width="80" prop="bundleFee" />
        <el-table-column show-overflow-tooltip :label="$t('是否出库')" align="center" prop="isOutWarehouse">
          <template slot-scope="{ row }">
            <div v-if="row.isOutWarehouse == 1">
              <!-- 是 -->
              {{ $t('是') }}
            </div>
            <div v-if="row.isOutWarehouse == 0">
              <!-- 否 -->
              {{ $t('否') }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="sku" align="center" prop="sku" :width="ListOfExpressWays.skuWidth">
          <template slot-scope="{ row }">
            <div class="sku-list">
              <div v-for="item in row.skus" class="sku-list-item">
                <div class="skuNo">{{ item.skuNo }}</div>
                <el-image
                  :key="Math.random()"
                  v-hover="item.imgUrl"
                  fit="contain"
                  style="width: 30px; height: 30px"
                  :src="item.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'"
                />
                <div>{{ item.orderSkuNum }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button @click="ListOfExpressWays.show = false">
          <!-- 关闭 -->
          {{ $t('关闭') }}
        </el-button>
      </div>
    </el-dialog>
    <!-- 捆包详情修改 修改订单包裹 -->
    <el-dialog
      :title="$t('修改快递')"
      destroy-on-close
      append-to-body
      :visible.sync="packageInfo.edit.show"
      width="600px"
      :before-close="() => (packageInfo.edit.show = false)"
    >
      <!-- *************************************搜索区************************************* -->
      <el-form
        :model="packageInfo.edit.form"
        ref="packageInfo.edit.form"
        size="small"
        label-width="100px"
        :rules="packageInfo.edit.rules"
      >
        <!-- 快递标识号 -->
        <el-form-item :label="$t('快递标识号')" prop="expressNo">
          <el-select
            filterable
            style="width: 100%"
            @change="getSelectTrilateralSize"
            v-model="packageInfo.edit.form.expressNo"
          >
            <el-option v-for="item in expressWayList" :label="item" :value="item" :key="item" />
          </el-select>
        </el-form-item>
        <!-- sgw,k尺寸 -->
        <el-form-item :label="$t('尺寸')" prop="expressNo">
          <el-select
            filterable
            style="width: 100%"
            :disabled="packageInfo.edit.form.expressNo !== 'sgw' && packageInfo.edit.form.expressNo !== 'K'"
            v-model="packageInfo.edit.form.trilateralSize"
          >
            <el-option v-for="item in getExpressWayList" :label="item" :value="item" :key="item" />
          </el-select>
        </el-form-item>
        <!-- 包裹份数 -->
        <el-form-item :label="$t('包裹份数')" prop="packageNum">
          <el-input v-model.number="packageInfo.edit.form.packageNum" type="number" clearable />
        </el-form-item>
        <!-- 运费 -->
        <el-form-item :label="$t('运费')" prop="deliveryFee">
          <el-input v-model.number="packageInfo.edit.form.deliveryFee" type="number" clearable />
        </el-form-item>

        <!-- 捆包费 -->
        <el-form-item :label="$t('捆包费用')" prop="bundleFee">
          <el-input type="number" v-model.number="packageInfo.edit.form.bundleFee" clearable />
        </el-form-item>
        <div style="margin-top: 20px">
          <el-checkbox size="medium" @change="remember" style="color: red">{{ $t('记录更正修改') }}</el-checkbox>
        </div>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="packageInfo.edit.show = false">
          <!-- 关闭 -->
          {{ $t('关闭') }}
        </el-button>
        <el-button type="primary" @click="confirmEditPackage">
          {{ $t('确认') }}
        </el-button>
      </div>
    </el-dialog>
    <!-- 导入 -->
    <Import
      action="/distribution/orderBatch/importPackageExpressNo"
      @success="getList"
      :show.sync="importInfo.show"
      :query="importInfo.query"
      :tip="$t('仅允许导入.csv格式文件')"
      accept=".csv"
    >
    </Import>
    <!-- 订单数量 -->
    <OrderNum :show.sync="packageInfo.order.show" :query="packageInfo.order.query" />
    <!-- 订单数量测试快递方式 -->
    <OrderNumType :show.sync="ListOfExpressWays.order.show" :ListData="ListOfExpressWays.orderList" />
    <!-- sku费用 -->
    <SkuFee :show.sync="skuFeeInfo.show" :query="skuFeeInfo.query" />
    <RepeatError :show.sync="repeatError.show" :formData="repeatError.formData" />
    <!-- 导出面单 -->
    <ExportExpressSheet
      action="/distribution/orderBatch/exportExpressSheet"
      templateUrl="distribution/orderBatch/downPackageExpressTemplate"
      :show.sync="exportExpressSheet.show"
    />
    <!-- 主单详情编辑 -->
    <EditMainOrder
      :show.sync="editMainOrder.show"
      :formData="editMainOrder.formData"
      @getList="
        () => {
          getdistributionOrder()
          getList()
        }
      "
    />

    <ExpressStatics
      :shop_type_list="shop_type_list"
      :batchIdList="tableCheck"
      :show.sync="expressStatics.show"
      @getList="getUnSendskuList"
      :formData="expressStatics.formData"
    />

    <!-- 支付弹框 支付详情-->
    <Pay :show.sync="pay.show" :formData="pay.formData" @getList="getList" @updataPayType="updataPayType">
      <template #header>
        <el-alert
          :title="
            $t('提前付款可以提前结束该申请的结算，一般用于帮助下次申请获得权限，提前付款只能付款未结束的全部数量')
          "
          show-icon
          :closable="false"
          effect="dark"
          style="margin-bottom: 20px"
          type="warning"
        >
        </el-alert>
      </template>
      <template #default="{ handlePayMethod }">
        <div style="margin: 20px 0" v-hasPermi="['distribution:bill:sellerBatchBeforeOfflinePay']">线下支付：</div>
        <div class="payContentOffline" v-hasPermi="['distribution:bill:sellerBatchBeforeOfflinePay']">
          <el-button
            :class="{ 'is-active': offlinePayTypestr == 1 }"
            @click="offlinePayType(1, handlePayMethod, 'offlineCash')"
            >现金支付</el-button
          >
          <el-button
            :class="{ 'is-active': offlinePayTypestr == 2 }"
            @click="offlinePayType(2, handlePayMethod, 'offlineTransfer')"
            >银行卡转账</el-button
          >
        </div>
        <!-- <div style="display: flex; justify-content: center; margin-top: 20px">
          <el-button type="primary" @click="confirmPayment" v-hasPermi="['system:skuSellerApply:handBeforePay']">
            {{ $t('确认支付') }}</el-button
          >
        </div> -->
      </template>
    </Pay>
    <PackageDetail :show.sync="packageDetail.show" :formData="packageDetail.formData" />
    <ShopSkuNum :show.sync="shopSkuNum.show" :formData="shopSkuNum.formData" />
    <!-- /**选择自派送 */ -->
    <SelectDispatch :show.sync="selectDispatch.show" :formData="selectDispatch.formData" @getList="getList" />
  </div>
</template>

<script>
import { sellerBatchBeforeOfflinePay, stockNotEnoughBatchBeforePay } from '@/api/distribution/sku/sellerApplicationList'
import Import from '@/components/Import/index.vue'
import OrderNum from './components/orderNum.vue'
import OrderNumType from './components/orderNumType.vue'
import SkuFee from './components/skuFee.vue'
import EditMainOrder from './components/editMainOrder.vue'
import RepeatError from './components/repeatError.vue'
import ExportExpressSheet from './components/exportExpressSheet.vue'
import handleSum from '@/utils/handleSum'
import { useDict } from '@/utils/useDict'
import ExpressStatics from './components/expressStatics.vue'
import Pay from '@/components/Pay/index.vue'
import PackageDetail from './components/packageDetail.vue'
import ShopSkuNum from './components/shopSkuNum.vue'
import SelectDispatch from './components/selectDispatch.vue'

import {
  tryPayBatch,
  orderBatchList,
  distributionOrderDelete,
  distributionOrder,
  importPlatformData,
  batchPackageRollback,
  distributorShopQueryList,
  orderBatch,
  unSendskuList,
  deleteOrderBatch,
  updateOrder,
  batchSkuList,
  updateStockFlag,
  generatePackage,
  selectTrilateralSize,
  orderPackageList,
  editOrderPackage,
  expressWay,
  preTestGeneratePackage,
  deletePackage,
} from '@/api/distribution/orderBatchs/index'
import { skuDistributorSellerApply } from '@/api/distribution/sku/cloudProduct'
import {
  batchBillPayHand,
  batchBillPayInfo,
  billList,
  getBillDetails,
  getDistrList,
  sellerBatchBillOfflinePay,
} from '@/api/bill/seller'
import { getToken } from '@/utils/auth'
import { checkPermi } from '@/utils/permission'
import RightOrWrong from '@/components/RightOrWrong/index.vue'
export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  name: 'OrderBatchs',
  components: {
    Pay,
    Import,
    OrderNum,
    OrderNumType,
    SkuFee,
    ExportExpressSheet,
    EditMainOrder,
    RightOrWrong,
    RepeatError,
    ExpressStatics,
    PackageDetail,
    ShopSkuNum,
    SelectDispatch,
  },
  data() {
    return {
      /**
       * 租户列表
       */
      distrList: [],
      /**选择自派送 */
      selectDispatch: {
        show: false,
        formData: {},
      },
      shopSkuNum: {
        show: false,
        formData: {},
      },
      packageDetail: {
        show: false,
        formData: {},
      },
      getExpressWayFlage: true,
      getExpressWayList: [], //k、sgw获取尺寸列表
      offlinePayTypestr: '', //支付方式
      pay: {
        show: false,
        formData: {},
      },
      tableCheckPay: [],
      /**详情 */
      prePay: {
        show: false,
        type: '',
        formData: {},
        idList: [],
      },
      expressStatics: {
        show: false,
        formData: {},
        shop_type_list: [],
      },
      ListOfExpressWays: {
        show: false,
        data: [],

        queryParams: {
          packageNo: '',
          timeBetween: [],
        },
        order: {
          show: false,
        },
      },
      isdisAbel: false,
      /**店铺类型列表 */
      shop_type_list: [],
      /**导入 */
      importInfo: {
        show: false,
        query: {
          // 1-黑猫，2-佐川，
          packageExpressType: '',
        },
      },
      editMainOrder: {
        show: false,
        formData: {},
      },
      exportExpressSheet: {
        show: false,
        formData: {},
      },
      showSearch: false,
      notAutoFitColums: ['shopName'],

      handleSum,
      repeatError: {
        show: false,
        formData: [],
      },
      skuFeeInfo: {
        show: false,
        query: {
          /**批次id */
          batchId: '',
          /**	sku编号 */
          skuNo: '',
        },
      },
      /**
       * 快递方式
       */
      expressWayList: [],
      /**捆包详情 */
      packageInfo: {
        show: false,
        data: [],
        skuWidth: 0,
        queryParams: {
          packageNo: '',
          deliveryNo: '',
          timeBetween: [],
        },
        /**订单 */
        order: {
          show: false,
          query: {
            packageNo: '',
            orderBatchId: '',
          },
        },
        /**修改 */
        edit: {
          show: false,
          form: {
            /**包裹id */
            id: '',
            /**	快递标识号 */
            expressNo: '',
            /**	运费 */
            deliveryFee: '',
            /**	捆包费 */
            bundleFee: '',
            /**包裹数量 */
            packageNum: '',
            /**记录更正修改 */
            resultChangeFlag: 0,
            /**三遍尺寸 */
            trilateralSize: '',
          },
          rules: {
            expressNo: [{ required: true, message: '请选择', trigger: 'blur' }],
            deliveryFee: [{ required: true, message: '请输入', trigger: 'blur' }],
            bundleFee: [{ required: true, message: '请输入', trigger: 'blur' }],
            packageNum: [{ required: true, message: '请输入', trigger: 'blur' }],
            trilateralSize: [{ required: true, message: '请选择', trigger: 'blur' }],
          },
        },
      },
      tableCheck: [],
      /**未生成包裹批次 聚合SKU数量  */
      unSendskuInfo: {
        show: false,
        data: [],
        pageTotal: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          skuNo: '',
          orderBatchId: '',
        },
      },
      curentDataID: '',

      orderBatchListInfor: [],
      batchData: {
        Show: false,
        formData: {},
      },
      shopIdList: [],
      /**导入的表单 */
      importDataForm: {
        /**下载煤炉（个人）模板 */
        showDownloadMercariTemplate: false,
        tip: '',
        alert: '',
        limit: 1,
        platformType: '',
        uplaodopen: false,
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/demo/demo/importData',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
      },

      distributorList: [],
      title: '',
      tableData: [],
      showDialog: false,
      /**数据总条数 */
      pageTotal: 0,
      loading: false,
      // 查询参数
      queryParams: {
        deliveryNo: '',
        pageNum: 1,
        pageSize: 10,
      },
      /** 主单详情 */
      mainOrderInfo: {
        show: false,
        data: [],
        skuWidth: 0,
        pageTotal: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderNo: '',
        },
        /**主单详情编辑 */
        editform: {
          receiveName: '',
          receivePhone: '',
          receivePostcode: '',
          id: '',
          address1: '',
          address2: '',
          address3: '',
          address4: '',
          address5: '',
          address6: '',
        },
        editRule: {
          receiveName: [{ required: true, message: '请输入', trigger: 'blur' }],
          receivePhone: [{ required: true, message: '请输入', trigger: 'blur' }],
          receivePostcode: [{ required: true, message: '请输入', trigger: 'blur' }],
          address1: [{ required: true, message: '请输入', trigger: 'blur' }],
          address2: [{ required: true, message: '请输入', trigger: 'blur' }],
          address3: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        /**显示主单详情编辑 */
        showEdit: false,
      },
      /**当前订单sku(聚合) */
      batchSkuInfo: {
        show: false,
        data: [],
        pageTotal: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          /**批次id */
          batchId: '',
          /**sku编号 */
          skuNo: '',
        },
      },
    }
  },
  computed: {
    platformType: function () {
      return this.shop_type_list.filter((i) => i.value == this.importDataForm.platformType)[0]?.label || ''
    },
  },
  created() {
    this.getList()
    this.getdistributorShop()
    useDict('shop_type').then(({ shop_type }) => {
      this.shop_type_list = shop_type.map((item) => {
        return {
          ...item,
          dictValue: +item.dictValue,
        }
      })
    })
    getDistrList().then((res) => {
      this.distrList = res.rows
    })
  },
  mounted() {
    document.addEventListener('visibilitychange', (e) => {
      if (document.hidden) {
      } else {
        this.$nextTick(() => this.$refs['TableRef']?.doLayout())
      }
    })
  },

  methods: {
    handleSelectDispatch() {
      this.selectDispatch.formData = { ...this.tableCheck[0] }
      this.selectDispatch.show = true
    },
    hanldeShopSkuNum(data) {
      this.shopSkuNum.formData = { ...data.formData }
      this.shopSkuNum.show = true
    },
    handleTryAutoPay() {
      this.$confirm(this.$t('确认尝试自动付款?'), this.$t('提示'), {
        type: 'warning',
      }).then(() => {
        const data = {
          batchList: this.tableCheck.map((i) => i.id),
        }
        tryPayBatch(data).then((res) => {
          const { code, data, msg } = res
          if (code === 200) {
            this.$message({ type: 'success', message: msg })
            this.getList()
          }
        })
      })
    },
    handleExportOverWeightPacage() {
      this.download(
        'distribution/orderBatch/exportOverweightPackage',
        {
          batchList: [this.curentDataID],
        },
        `overweightPackage_${new Date().getTime()}.xlsx`,
      )
    },
    handlePackageDetail(row) {
      this.packageDetail.formData = row
      this.packageDetail.show = true
    },
    handleRowClassName(row) {
      if (row.delFlag == 2) {
        return 'delFlag-2'
      }
    },
    deletePackage(row) {
      const html = `
                    <div style="color:red">
                      <div>提示：</div>
                      <div>请谨慎删除！！！</div>
                      <div>删除包裹会删除包裹以及包裹中的订单</div>
                      <div>对于已经付款的订单，将已积分形式返回运费捆包费和sku费用，如果有的话，卖家库存将会退回</div>
                    </div>
                   `
      this.$alert(html, this.$t('提示'), {
        dangerouslyUseHTMLString: true,
      }).then(() => {
        deletePackage(row.id).then((res) => {
          const { code, data, msg } = res
          if (code === 200) {
            this.$message({ type: 'success', message: msg })
            this.getOrderPackageList()
          }
        })
      })
    },
    remember(val) {
      if (val) {
        this.packageInfo.edit.form.resultChangeFlag = 1
      } else {
        this.packageInfo.edit.form.resultChangeFlag = 0
      }
    },
    getSelectTrilateralSize(expressNo) {
      this.$set(this.packageInfo.edit.form, 'trilateralSize', '')
      if (expressNo == 'K' || expressNo == 'sgw') {
        selectTrilateralSize({ expressNo }).then((res) => {
          if (res.code === 200) {
            this.getExpressWayList = res.data
          }
        })
      }
    },
    /*skw尺寸列表 */
    getExpressWay(expressNo) {
      selectTrilateralSize({ expressNo }).then((res) => {
        if (res.code === 200) {
          this.getExpressWayList = res.data
        }
      })
    },
    updataPayType(selectPayChannel) {
      if (selectPayChannel) {
        this.offlinePayTypestr = selectPayChannel == 'offlineCash' ? 1 : 2
        let that = this
        this.$modal
          .confirm(
            `是否确认${this.offlinePayTypestr == 1 ? '现金支付' : this.offlinePayTypestr == 2 ? '银行卡转账' : ''}支付`,
          )
          .then(function () {
            return sellerBatchBeforeOfflinePay({
              id: that.prePay.payInfo.businessId,
              offlinePayType: that.offlinePayTypestr,
            })
          })
          .then(() => {
            this.$message({ type: 'success', message: '操作成功' })
            // this.cancel()
            // this.$emit('getList')
            this.getList()
            this.pay.show = false
          })
      } else {
        this.offlinePayTypestr = ''
      }
    },
    /**线下支付方式 */
    offlinePayType(offlinePayType, handlePayMethod, payTypeStr) {
      this.offlinePayTypestr = offlinePayType
      handlePayMethod({ payChannel: payTypeStr })
    },
    handlePay(row) {
      this.tableCheckPay = [row]
      this.handleBatchPrePay()
    },
    /**付款 handlePay*/
    handleBatchPrePay() {
      const idList = this.tableCheckPay.map((i) => i.skuId)
      this.prePay.type = 'batch'
      this.prePay.idList = idList

      stockNotEnoughBatchBeforePay({ idList: this.prePay.idList }).then((res) => {
        this.prePay.payInfo = res.data
        this.pay.show = true
        this.pay.formData = res.data
      })
    },
    /**去申请 */
    goToApply(row) {
      if (!row.applyNum) {
        this.$message.error('请输入申请数量')
      } else {
        this.$confirm('是否提交申请', '申请', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            skuDistributorSellerApply({ skuId: row.skuId, applyNum: row.applyNum })
              .then((res) => {
                row.applyNum = ''
                this.$message({
                  type: 'success',
                  message: '申请成功!',
                })
                this.getUnSendskuList()
              })
              .catch(() => {
                row.applyNum = ''
              })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消申请',
            })
          })
      }
    },
    /**跳转到其他页面(去申请去付款) */
    // jumptOhterPage(path, row) {
    //   this.unSendskuInfo.show = false
    //   const routeObject = {
    //     path, // 替换成你想要跳转的路径
    //     query: {
    //       goToBeforePaySku: row.skuNo,
    //     },
    //   }
    //   const targetUrl = this.$router.resolve(routeObject).href
    //   window.open(targetUrl, '_blank')
    // },
    /**过滤不可选中数据 */
    selectable(row, index) {
      return true
      // if (value.isPackage == 1) {
      //   return true
      // } else {
      //   return false
      // }
    },
    /**快递统计 */
    handleExpressStatics() {
      this.expressStatics.formData = {}
      this.expressStatics.show = true
      // this.$confirm(this.$t('只有已生成包裹才能查看快递统计?'), this.$t('提示'), {
      //   type: 'warning',
      // }).then(() => {
      //   const rows = [...this.tableCheck.filter((i) => i.isPackage != 1)]
      //   this.$refs['TableRef'].toggleRowSelection(this.tableCheck[0])
      //   console.log(`rows ==>`,JSON.parse(JSON.stringify(rows)));
      //   this.expressStatics.formData = {}
      //   this.expressStatics.show = true
      // })
    },
    downloadMercariTemplate() {
      this.download('/distribution/orderMercariIndividual/exportTemp', {}, `tempDownload_${new Date().getTime()}.xlsx`)
    },
    /**聚合弹框搜索重置 */
    resetSkuNo() {
      this.batchSkuInfo.queryParams.skuNo = ''
      this.getBatchSkuList()
    },
    /**批次回滚 */
    backBatch(data) {
      batchPackageRollback({ id: data }).then((res) => {
        this.$message.success(res.msg)
        this.getList()
      })
    },
    setOrderNum(row) {
      this.ListOfExpressWays.order.show = true
      this.ListOfExpressWays.orderList = row.orderList
    },
    /**获取快递方式测试列表 */
    getpreTestGeneratePackage() {
      preTestGeneratePackage({ id: this.curentDataID }).then((res) => {
        const { code, data } = res
        if (code === 200) {
          this.ListOfExpressWays.data = data
          let maxLength = 0
          data.map((i) => {
            if (i.skus && i.skus.length > maxLength) {
              maxLength = i.skus.length
            }
          })
          this.ListOfExpressWays.skuWidth = maxLength * 150
          this.packageInfo.skuWidth = maxLength * 150
        }
      })
    },
    /**获取测试快递方式 */
    handlePackageNumTest() {
      this.getpreTestGeneratePackage()
      this.ListOfExpressWays.show = true
    },
    handleTypeChange(type) {
      // 亚马逊
      if (type == '1') {
        this.importDataForm.limit = 2
      }
    },
    handleUpload() {
      const files = this.$refs['uploadRef'].uploadFiles
      if (files.length == 0) {
        return this.$message.error('请上传文件')
      }
      // 亚马逊
      if (this.importDataForm.platformType == '1') {
        if (files.length !== 2) {
          return this.$message.error('请上传两个文件')
        } else {
          this.onChange(files)
        }
      } else {
        this.onChange(files)
      }
    },
    handleAccept() {
      //  /**
      //  * 亚马逊
      //  */
      // AMAZON(DsOrderAmazonImportService.AMAZON, "1", ".txt"),
      // /**
      //  * 乐天
      //  */
      // LOTTE(DsOrderLotteImportService.LOTTE, "2", ".csv"),
      // /**
      //  * 雅虎拍卖
      //  */
      // ZENMARKET("Zenmarket", "3", ".xlsx"),
      // /**
      //  * 雅虎商城
      //  */
      // YAHOO(DsOrderYahooImportService.YAHOO, "4", ".xlsx"),
      // /**
      //  * 煤炉(法人)
      //  */
      // MERCARI_LP(DsOrderMercariImportService.MERCARI_LP, "5", ".csv"),
      // /**
      //  * 沃尔玛
      //  */
      // WALMART("Walmart", "6", ".csv"),
      // /**
      //  * 煤炉(个人)
      //  */
      // MERCARI_P("MercariP", "7", ".csv");
      // /**
      //  * 煤炉(个人)
      //  */
      // MERCARI_P("Qoo10", "8", ".csv");
      switch (+this.importDataForm.platformType) {
        case 1:
          return '.txt'
        case 2:
          return '.csv'
        case 3:
          return '.xlsx'
        case 4:
          return '.xlsx'
        case 5:
          return '.csv'
        case 6:
          return '.csv'
        case 7:
          return '.xlsx,.xls'
        case 8:
          return '.csv'

        default:
          return '.csv, .txt'
      }
    },
    /** 导出面单*/
    handleExportExpressSheet() {
      this.exportExpressSheet.show = true
    },

    resetFormData() {
      this.mainOrderInfo.queryParams.orderNo = ''
      this.getdistributionOrder()
    },

    /**捆包详情修改 */
    confirmEditPackage() {
      const data = JSON.parse(JSON.stringify(this.packageInfo.edit.form))
      this.$refs['packageInfo.edit.form'].validate((valid) => {
        if (valid) {
          editOrderPackage(data).then((res) => {
            const { code, msg } = res
            if (code === 200) {
              this.$message({ type: 'success', message: msg })

              this.packageInfo.edit.show = false
              this.getOrderPackageList()
            }
          })
        }
      })
    },
    /**捆包详情修改 */
    editPackage(row) {
      expressWay().then((res) => {
        const { code, data } = res
        if (code === 200) {
          this.expressWayList = data
          this.packageInfo.edit.show = true
          /************************赋值***********************/
          this.packageInfo.edit.form.id = row.id
          this.packageInfo.edit.form.deliveryFee = row.deliveryFee
          this.packageInfo.edit.form.bundleFee = row.bundleFee
          this.packageInfo.edit.form.expressNo = row.deliveryWayFinal
          this.packageInfo.edit.form.packageNum = row.packageNum
          this.packageInfo.edit.form.trilateralSize = row.trilateralSize
          // 运费 捆包费用 保留整数
          this.packageInfo.edit.form.deliveryFee = (+this.packageInfo.edit.form.deliveryFee || 0).toFixed()
          this.packageInfo.edit.form.bundleFee = (+this.packageInfo.edit.form.bundleFee || 0).toFixed()
          if (row.deliveryWayFinal == 'K' || row.deliveryWayFinal == 'sgw') {
            this.getExpressWay(row.deliveryWayFinal)
          } else {
            this.$set(this.packageInfo.edit.form, 'trilateralSize', '')
          }
          this.remember(false)
        }
      })
    },
    getOrderPackageList() {
      orderPackageList({ ...this.packageInfo.queryParams, orderBatchId: this.curentDataID }).then((res) => {
        const { code, rows } = res
        if (code === 200) {
          console.log(`res.rows ==>`, JSON.parse(JSON.stringify(rows)))
          this.packageInfo.data = rows
          let maxLength = 0
          rows.map((i) => {
            if (i.skus && i.skus.length > maxLength) {
              maxLength = i.skus.length
            }
          })
          this.packageInfo.skuWidth = maxLength * 200
        }
      })
    },
    /**
     * 包裹数量
     */
    async handlePackageNum() {
      await this.getOrderPackageList()
      this.packageInfo.show = true
    },
    /**发送通知 */
    isautoPackage(row) {
      console.log(`row ==>`, JSON.parse(JSON.stringify(row)))
      let fileType = ''
      switch (row.shopType) {
        case 1:
          fileType = 'txt'
          break
        case 2:
          fileType = 'csv'
          break
        case 3:
          fileType = 'xlsx'
          break
        case 4:
          fileType = 'xlsx'
          break
        case 5:
          fileType = 'csv'
          break
        case 6:
          fileType = '沃尔玛'
          break
        case 7:
          fileType = 'csv'
          break
        default:
          break
      }
      this.download(
        '/distribution/orderBatch/sendMsgExport',
        { orderBatchId: row.id, shopType: row.shopType },
        `${row.shopName}_${new Date().toLocaleDateString()}_${new Date().getTime()}.${fileType}`,
      ).then(() => {
        this.getList()
      })
    },
    generatePackage() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)',
      })
      // updateStockFlag()
      //   .then((res) => {
      //     loading.close()
      //     this.$message({ type: 'success', message: res.msg })

      //     this.getList()
      //   })
      //   .catch(() => {
      //     loading.close()
      //   })
      const data = {
        batchList: this.tableCheck.map((i) => i.id),
      }
      generatePackage(data)
        .then((res) => {
          const { code, data, msg } = res
          if (code === 200) {
            this.$message({ type: 'success', message: msg })
            // 以前改成生成包裹后自动导出包裹，现在这个功能不要了，还是分成两部
            // this.checkFileDataExprort()
            this.getList()
            loading.close()
          }
        })
        .catch(() => {
          loading.close()
        })
    },
    /**导出包裹 */
    checkFileDataExprort() {
      const data = {
        batchList: this.tableCheck.map((i) => i.id),
      }
      this.download('/distribution/orderBatch/exportPackage', data, `${new Date().getTime()}.xlsx`)
      this.getList()
    },
    /**更新库存核销 */
    relaodUpdateStockFlag() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)',
      })
      updateStockFlag()
        .then((res) => {
          loading.close()
          this.$message({ type: 'success', message: res.msg })

          this.getList()
        })
        .catch(() => {
          loading.close()
        })
    },
    /**当前订单sku(聚合) */
    showBactchSku() {
      this.curentDataID
      this.getBatchSkuList()
      this.batchSkuInfo.show = true
    },
    getBatchSkuList() {
      batchSkuList(this.batchSkuInfo.queryParams).then((res) => {
        this.batchSkuInfo.data = res.rows
        this.batchSkuInfo.pageTotal = res.total
      })
    },
    handleReceiveAddress(row) {
      return (
        (row.address1 || '') +
        (row.address2 || '') +
        (row.address3 || '') +
        (row.address4 || '') +
        (row.address5 || '') +
        (row.address6 || '')
      )
    },
    /**编辑主单 */
    handleEditMainOrder(row) {
      const data = JSON.parse(JSON.stringify(row))
      Object.keys(data).forEach((key) => {
        this.editMainOrder.formData[key] = data[key]
      })
      this.editMainOrder.show = true
    },

    handleBatchDelete(id) {
      deleteOrderBatch(id).then((res) => {
        const { code, data, msg } = res
        if (code === 200) {
          this.$message({ type: 'success', message: msg })
          this.getList()
        }
      })
    },
    handleUnSendsku(row) {
      if (row) {
        this.unSendskuInfo.queryParams.orderBatchId = row.id
      } else {
        this.unSendskuInfo.queryParams.orderBatchId = ''
      }
      this.unSendskuInfo.show = true
      this.getUnSendskuList()
    },
    getUnSendskuList() {
      unSendskuList(this.unSendskuInfo.queryParams).then((res) => {
        this.unSendskuInfo.data = res.rows || []
        this.unSendskuInfo.pageTotal = res.total
      })
    },
    /**删除订单 */
    handleDelete(id) {
      distributionOrderDelete(id).then((res) => {
        if (res.code == 200) {
          this.$message({ type: 'success', message: res.msg })

          this.lookOrderInfor()
        }
      })
    },

    /**点击展示主订单详情 */
    lookOrderInfor() {
      this.mainOrderInfo.queryParams.orderNo = ''
      this.mainOrderInfo.show = true
      this.getdistributionOrder()
    },
    getdistributionOrder() {
      distributionOrder({
        orderNo: this.mainOrderInfo.queryParams.orderNo,
        orderBatchId: this.curentDataID,
      }).then((res) => {
        if (res.code == 200) {
          this.mainOrderInfo.data = res.rows
          let maxLength = 0
          res.rows.map((i) => {
            if (i.skus.length > maxLength) {
              maxLength = i.skus.length
            }
          })
          this.mainOrderInfo.skuWidth = maxLength * 170
          this.mainOrderInfo.pageTotal = res.total
        }
      })
    },
    batchDataHandleClose() {
      this.batchData.Show = !this.batchData.Show
      // this.batchData = {}
    },
    showShopName(value) {
      this.curentDataID = value.id
      this.batchSkuInfo.queryParams.batchId = value.id
      this.batchData.formData = value
      this.batchData.Show = !this.batchData.Show
      /******************sku费用*******************/
      this.skuFeeInfo.query.batchId = value.id
      console.log(` ==>`, JSON.parse(JSON.stringify(this.skuFeeInfo.query)))
      /******************sku费用end*******************/
      if (this.batchData.Show) {
        orderBatch(value.id).then((res) => {
          if (res.code == 200) {
            let {
              id,
              orderNum,
              turnoverAll,
              commissionAll,
              skuCateNum,
              skuNum,
              skuCost,
              packageNum,
              shopSkuNum,
              packageCost,
              packageBaleCost,
              taxAll,
            } = res.data
            this.$set(this.batchData, 'shopSkuNum', shopSkuNum)
            this.$set(this.batchData, 'taxAll', taxAll)
            this.$set(this.batchData, 'id', id)
            this.$set(this.batchData, 'orderNum', orderNum)
            this.$set(this.batchData, 'turnoverAll', turnoverAll)
            this.$set(this.batchData, 'commissionAll', commissionAll)
            this.$set(this.batchData, 'skuCateNum', skuCateNum)
            this.$set(this.batchData, 'skuNum', skuNum)
            this.$set(this.batchData, 'skuCost', skuCost)
            this.$set(this.batchData, 'packageNum', packageNum)
            this.$set(this.batchData, 'packageCost', packageCost)
            this.$set(this.batchData, 'packageBaleCost', packageBaleCost)
            // this.batchData.id = id,
            // this.batchData.orderNum = orderNum,
            // this.batchData.turnoverAll = turnoverAll,
            // this.batchData.commissionAll = commissionAll,
            // this.batchData.skuCateNum = skuCateNum,
            // this.batchData.skuNum = skuNum,
            // this.batchData.skuCost = skuCost,
            // this.batchData.packageNum = packageNum,
            // this.batchData.packageCost = packageCost,
            // this.batchData.packageBaleCost = packageBaleCost
          }
        })
      }
    },
    /**获取店铺下拉 */
    getdistributorShop() {
      distributorShopQueryList().then((res) => {
        if (res.code == 200) {
          this.shopIdList = res.data
        }
      })
    },
    onChange(file) {
      console.log(`file ==>`, file)
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)',
      })
      const formData = new FormData()
      for (const item of file) {
        formData.append('files', item.raw)
      }
      console.log(`formData ==>`, formData)
      // formData.append('platformType', this.importDataForm.platformType)
      importPlatformData(formData, this.importDataForm.platformType)
        .then((res) => {
          if (res.code == 200) {
            if (res.data.failNum > 0) {
              this.repeatError.formData = JSON.parse(res.data.msg) || []
              this.repeatError.show = true
            } else {
              this.$message({ type: 'success', message: res.msg })
            }
          }
          this.importDataForm.platformType = ''
          this.importDataForm.uplaodopen = !this.importDataForm.uplaodopen
          this.getList()
        })
        .catch((err) => {
          this.importDataForm.platformType = ''
          this.importDataForm.uplaodopen = !this.importDataForm.uplaodopen
        })
        .finally(() => loading.close())
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    /**提交导入数据 */
    checkFileData() {
      if (this.importDataForm.platformType == '') {
        this.$message.error('请先选择导入订单类型')
      } else {
        // 亚马逊
        if (this.importDataForm.platformType == '1') {
          this.importDataForm.tip = `
          <span>请<span style="color:red;"> 按照顺序 </span>先上传<span style="color:red;"> 未发货订单 </span>再上传<span style="color:red;"> 新订单 </span></span>
          `
          this.importDataForm.alert =
            '<span>文件格式为: <span style="font-weight: bold;">店铺名--1--日期</span>, 如: <br/><span style="font-weight: bold;">abc--1--2023.11.07<br/> abc--2--2023.11.08</span></span>'
        } else {
          this.importDataForm.alert =
            '<span>文件格式为: <span style="font-weight: bold;">店铺名--日期</span>, 如:<br/><span style="font-weight: bold";>abc--2023.11.07</span></span>'
        }

        // 煤炉(个人)
        if (this.importDataForm.platformType == '7') {
          this.importDataForm.showDownloadMercariTemplate = true
        } else {
          this.importDataForm.showDownloadMercariTemplate = false
        }

        //
        this.importDataForm.uplaodopen = !this.importDataForm.uplaodopen
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryParams')
      Object.keys(this.queryParams).forEach((key) => (this.queryParams[key] = ''))
      this.queryParams.pageSize = 10
      this.queryParams.pageNum = 1
      this.handleQuery()
    },
    handleType(type) {
      // 订单平台类型 1-亚马逊 2-乐天 3-雅虎拍卖 4-雅虎 5-煤炉(法人) 6-沃尔玛  7-煤炉(个人)
      // switch (shopType) {
      //   case 1:
      //     return '亚马逊 '
      //   case 2:
      //     return '乐天'
      //   case 3:
      //     return '雅虎拍卖'
      //   case 4:
      //     return '雅虎商城'
      //   case 5:
      //     return '煤炉(法人)'
      //   case 6:
      //     return '沃尔玛'
      //   case 7:
      //     return '煤炉(个人)'
      //   case 9:
      //     return '线下店铺'
      //   default:
      //     break
      // }
      const index = this.shop_type_list.findIndex((i) => i.dictValue == type)
      return this.shop_type_list[index]?.dictLabel
    },
    handleOpen() {},

    /** 查询菜单列表 */
    getList() {
      this.loading = true
      const params = JSON.parse(JSON.stringify(this.queryParams))
      const { timeBetween } = params
      const startDate = timeBetween ? timeBetween[0] : ''
      const endDate = timeBetween ? timeBetween[1] : ''
      delete params.timeBetween
      const data = {
        ...params,
        startDate,
        endDate,
      }
      orderBatchList(data).then((res) => {
        this.tableData = res.rows
        this.pageTotal = res.total
        this.loading = false
        this.isdisAbel = checkPermi(['distribution:order:sendMsgExport'])
        this.$nextTick(() => this.$refs['TableRef']?.doLayout())
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
  },
}
</script>
<style lang="scss" scoped>
.importantData {
  ::v-deep .el-input--mini {
    .el-input__inner {
      border-radius: 4px 0 0 4px !important;
    }
  }
}

.importantDataBtn {
  border-radius: 0 4px 4px 0 !important;
}

.sku-list {
  display: flex;
  white-space: nowrap;

  &-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #eee;
    border-radius: 3px;
    padding: 0 2px;
    margin-right: 5px;
    gap: 8px;

    .skuNo {
      white-space: nowrap;
    }
  }
}

.FitHeader {
  .el-table {
    .cell,
    th > .cell {
      white-space: nowrap;
      width: fit-content;
    }
  }
  .ex-table_column_not-auto-fit .cell {
    width: 100% !important;
  }
}
</style>
